// import render from '@feidao/web/atom/nodejs/render/render';
// import get_menus from '@feidao/web/atom/nodejs/authorization/get-menus-1';

// import get_menus from '@dfeidao/atom-nodejs/authorization/get-menus';
import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import render from '@dfeidao/atom-nodejs/render/render';
// import { productid } from '../../atom/config';
////////////////////////////////////////////////////////////////////////////////
// import presentations
////////////////////////////////////////////////////////////////////////////////
interface IMenu {
	menu_no: string;
	icon: string;
	menu_name: string;
	client_type: string;
	parent_no: string;
	productid: string;
	systemid: string;
	package_url: string;
	auth_code: number;
	c: IMenu[];
}
export default async function na001(fd: IFeidaoAiNodejsComponent) {
	// 数据结构
	// const datas = await get_menus(fd.data.msg, fd.data.headers, productid, '3') as IMenu[];
	const datas = [
		{
			menu_no: '1000',
			icon: '',
			menu_name: '首页',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'index.html'
		},
		{
			menu_no: '1001',
			icon: '',
			menu_name: '客户管理',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: ''
		},
		{
			menu_no: '100101',
			icon: '',
			menu_name: '客户信息',
			client_type: '3',
			parent_no: '1001',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'customer-info.html'
		},
		{
			menu_no: '100102',
			icon: '',
			menu_name: '抓拍结果',
			client_type: '3',
			parent_no: '1001',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'snap-result.html'
		},
		{
			menu_no: '100103',
			icon: '',
			menu_name: '客户接待',
			client_type: '3',
			parent_no: '1001',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'customer-recept.html'
		},
		// {
		// 	menu_no: '100104',
		// 	icon: '',
		// 	menu_name: '数据分析',
		// 	client_type: '3',
		// 	parent_no: '1001',
		// 	productid: 'wang',
		// 	systemid: 'face_sys',
		// 	package_url: 'data-analysis.html'
		// },
		{
			menu_no: '1002',
			icon: '',
			menu_name: '风控规则',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'control-rules.html'
		},
		{
			menu_no: '1003',
			icon: '',
			menu_name: '渠道管理',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'channel-manage.html'
		},
		{
			menu_no: '1004',
			icon: '',
			menu_name: '基础信息管理',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: ''
		},
		{
			menu_no: '100401',
			icon: '',
			menu_name: '人员管理',
			client_type: '3',
			parent_no: '1004',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'person-manage.html'
		},
		{
			menu_no: '100402',
			icon: '',
			menu_name: '客户调换管理',
			client_type: '3',
			parent_no: '1004',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'customer-audit.html'
		},
		{
			menu_no: '100403',
			icon: '',
			menu_name: '项目管理',
			client_type: '3',
			parent_no: '1004',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'project-manage.html'
		},
		{
			menu_no: '100404',
			icon: '',
			menu_name: '设备管理',
			client_type: '3',
			parent_no: '1004',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'equipment-manage.html'
		},
		{
			menu_no: '1005',
			icon: '',
			menu_name: '租户管理',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'tenant-manage.html'
		},
		{
			menu_no: '1006',
			icon: '',
			menu_name: '日志管理',
			client_type: '3',
			parent_no: '',
			productid: 'wang',
			systemid: 'face_sys',
			package_url: 'log-manage.html'
		}
	] as IMenu[];
	// 数据处理
	const t = (p: string) => {
		return datas.filter((d) => {
			return d.parent_no === p;
		});
	};
	const d1 = datas.filter((d) => {
		d.c = t(d.menu_no);
		return d.parent_no === '';
	});

	let r = ``;
	const t1 = (
		data: Array<{
			icon: string
			package_url: string
			menu_name: string
			c: [] | IMenu[]
		}>,
		level: number
	) => {
		data.forEach((d) => {
			//  data=` + encodeURIComponent(JSON.stringify(d)) + `
			// const bc = d.color ? 'background-color: ' + d.color + ';' : '';
			if (d.c.length === 0) {
				let str = ``;
				str =
					`<div name="div` +
					level +
					`" class="` +
					level +
					` twomemu" style="display: none;">
					<div name="xz" class="menu-item" flag="0" data-feidao-l="` +
					level +
					`" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003">
					<a href="` +
					(d.package_url ? d.package_url : 'javascript:void(0)') +
					`" class="twomemu1">
						<div>
							<i class="iconfont icon-icon-down ` +
					d.icon +
					` font18 text-c display-ib" style="width: 40px;"></i>
							<span class="menu` +
					level +
					`_name display-ib color-white">` +
					d.menu_name +
					`</span>
						</div>
						</a>
					</div>
				</div>`;
				r += str;
			} else {
				let str = ``;
				str =
					`<div name="div` +
					level +
					`" class="` +
					level +
					` twomemu" style="display: none;">
					<div name="xz" class="menu-item" flag="0" data-feidao-l="` +
					level +
					`" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003">
					<a href="` +
					(d.package_url ? d.package_url : 'javascript:void(0)') +
					`" class="twomemu1">
						<div>
							<i class=iconfont icon-icon-down ` +
					d.icon +
					` font18 text-c display-ib" style="width: 40px;"></i>
							<span class="menu` +
					level +
					`_name display-ib">` +
					d.menu_name +
					`</span>
						</div></a>
					</div><div data-feidao-level="` +
					(level + 1) +
					`">`;
				r += str;
				t1(d.c, level + 1);
			}
		});
		r += `</div></div>`;
	};
	// 第一级目录
	d1.forEach(
		(d: {
			package_url: string
			icon: string
			menu_name: string
			c: IMenu[]
		}) => {
			// const bc = d.background ? 'background: rgb(233, 97, 0);' : 'background: rgb(233, 97, 0);';
			//  data=` + encodeURIComponent(JSON.stringify(d)) + `
			if (d.c.length === 0) {
				r +=
					`<div data-feidao-level="1">
				<div  flag="0" data-feidao-l="1" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003" class="menu-item">
				<a href="` +
					(d.package_url ? d.package_url : 'javascript:void(0)') +
					`" class="onememu">
				<span class='color-white'>
					<i class="font20 iconfont icon c dispaly-ib text-c" style="width: 41px;"></i>
					<span class="text-l display-ib color-white">` +
					d.menu_name +
					`</span>
				</span>
				<i class="iconfont icon-down dispaly-ib text-c font14" style=""></i>
				</a>
		</div>`;
			} else {
				r +=
					`<div data-feidao-level="1">
				<div  flag="0" data-feidao-l="1" data-feidao-actions="click:eu-001,mouseout:eu-002,mouseover:eu-003" class="menu-item">
				<a href="` +
					(d.package_url ? d.package_url : 'javascript:void(0)') +
					`" class="onememu">
				<span>
					<i class="font20 iconfont icon ` +
					d.icon +
					` dispaly-ib text-c" style="width: 41px;"></i>
					<span class="text-l display-ib color-white">` +
					d.menu_name +
					`</span>
				</span>
				<i class="iconfont cursor-p icon-down font14 display-ib text-c" data-feidao-id="icon"></i></a>
		</div><div data-feidao-level="2">`;
				t1(d.c, 2);
			}
			r += '</div>';
		}
	);

	render(fd.data.node, '', r, 'P01');
}
